package autowored;

import autowored.pet.Cat;
import autowored.pet.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.support.NullValue;

import javax.annotation.Resource;

public class Human {

//注解注入
    @Resource(name = "cat007")
//    @Resource注入是官方注解,推荐使用,默认ByName,name参数可指定bean对象
    private Cat cat;
    @Autowired(required = false)
    //注入可以为空
    @Qualifier(value = "dog1")
    //当配置文件有多个对象时,Autowired会使用set方法进行ByName匹配,
    // 无set方法只能使用@Qualifier注解选择bean对象
    private Dog dog;
    private String name;

    public Cat getCat() {
        return cat;
    }
// 使用注解时,可忽略set方法
//    public void setCat(Cat cat) {
//        this.cat = cat;
//    }

    public Dog getDog() {
        return dog;
    }

//    public void setDog(Dog dog) {
//        this.dog = dog;
//    }

    @Override
    public String toString() {
        return "Human{" +
                "cat=" + cat +
                ", dog=" + dog +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
